package com.example.movie.common.dao

import androidx.room.*
import com.example.movie.common.entity.Order
import com.example.movie.common.entity.User

@Dao
interface UserDao {

    @Query("SELECT * FROM user")
    fun getAll(): List<User>

    @Query("SELECT * FROM user WHERE uid IN (:userIds)")
    fun loadAllByIds(userIds: IntArray): List<User>

    @Insert
    fun insertAll(vararg users: User)

    @Delete
    fun delete(user: User)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOrders(orders: List<Order>)

    @Query("DELETE FROM `Order`")
    fun deleteAllOrders()

    @Query("SELECT DISTINCT orderId FROM `Order` WHERE state = :state ORDER BY playDay DESC ,startTime ASC")
    fun getOrderIdsByState(state: String): List<Long>

    /**
     * 根据订单id查询购买的电影票，
     */
    @Query("SELECT * FROM `Order` WHERE orderId = :orderId ")
    fun getTicketOrders(orderId: Long): List<Order>

}
    